#pragma once
#ifndef __ECG_STORE_H__
#define __ECG_STORE_H__
#ifdef USE_ECG
#include <stdint.h>
#include <stdbool.h>
#include "ecg_common.h"
#define ECG_STORE_PATH "ecg"
#define ECG_STORE_TEMP_PATH "ecg_temp"

#define ECG_STORE_ECG_TEMP ECG_STORE_TEMP_PATH "/ecg"
#define ECG_STORE_PPG_TEMP ECG_STORE_TEMP_PATH "/ppg"
#define ECG_STORE_HR_TEMP ECG_STORE_TEMP_PATH "/hr"

#define ECG_STORE_MERGE_TEMP ECG_STORE_TEMP_PATH "/merge"
#define ECG_STORE_RECORD_FMT ECG_STORE_PATH "/%u"
#define ECG_STORE_TEMP_COUNT (ECG_SAMPLE_FREQ * 3)
#define PPG_STORE_TEMP_COUNT (PPG_SAMPLE_FREQ * 3)

#define ECG_STORE_LOCK_COUNT (ECG_SAMPLE_FREQ)
#define PPG_STORE_LOCK_COUNT (PPG_SAMPLE_FREQ)

#define ECG_STORE_COPY_TEMP_SIZE (1024)

typedef struct __ecg_store_t
{
    int16_t ecg_temp_buff[ECG_STORE_TEMP_COUNT];
    int16_t ecg_lock_buff[ECG_STORE_LOCK_COUNT];
    int ecg_temp_count;
    int ecg_lock_count;

    int8_t hr_temp_buff[PPG_STORE_TEMP_COUNT];
    int8_t hr_lock_buff[PPG_STORE_LOCK_COUNT];
    int hr_temp_count;
    int hr_lock_count;

    int ppg_temp_buff[PPG_STORE_TEMP_COUNT];
    int ppg_lock_buff[PPG_STORE_LOCK_COUNT];
    int ppg_temp_count;
    int ppg_lock_count;

    bool ecg_lock_by_process;
    bool ppg_lock_by_process;
    bool hr_lock_by_process;

    bool is_write_ppg; //!< false 表示第一个值
    bool is_write_ecg; //!< false 表示第一个值
    int last_ecg_decompression_value;
    int last_ppg_decompression_value;
    int16_t sbp;
    int16_t dbp;
    uint32_t start_time;
} ecg_store_t;
void ecg_store_init(void);

bool ecg_store_create(ecg_store_t *p_ecg_store);

bool ecg_store_put_ecg(ecg_store_t *p_ecg_store, int16_t value);

bool ecg_store_put_ppg(ecg_store_t *p_ecg_store, uint8_t hr, int ppg);

bool ecg_store_put_bp(ecg_store_t *p_ecg_store, uint8_t sbp, uint8_t dbp);

void ecg_store_process(void);

bool ecg_store_save(ecg_store_t *p_ecg_store);

bool ecg_store_del(ecg_store_t *p_ecg_store);

int ecg_store_get_list(uint32_t *list_buff, int buff_count);
void ecg_store_clear(void);
#endif //!< #ifdef USE_ECG
#endif //!<__ECG_STORE_H__
